-- @owner: wan005
-- @date: 2024-08-12
-- @testpoint: trim()函数作为对象名的测试,部分测试点合理报错

--prestep1:切换B库;expect:执行成功
@conn PrimaryDbBmode;
show sql_compatibility;

--step1:作为列名;expect:成功
drop table if exists trim_test cascade;
create table trim_test(trim text);
insert into trim_test values('0');

--step2:作为索引名;expect:成功
create index trim on trim_test(trim);
drop index trim;

--step3:作为表名;expect:成功
drop table if exists trim cascade;
create table trim(trim text);

--step4:作为数据库名;expect:成功
drop database if exists trim;
create database trim;
drop database trim;

--step5:作为外部数据源名;expect:成功
drop data source if exists trim;
create data source trim;
drop data source trim;

--step6:作为自定义函数名;expect:报错
create or replace function trim(c1 int)
returns int
as  $$
begin
    return c1;
end;
$$language plpgsql;
/

--step7:作为存储过程名;expect:报错
drop table if exists t_trim_0019;
create table t_trim_0019(c1 text);
CREATE OR REPLACE PROCEDURE trim(P1 IN text) AS
BEGIN
insert into t_trim_0019 values ('00001');
raise info '测试trim作为存储过程名';
END;
/

--step8:作为角色名;expect:成功
drop role if exists trim;
create role trim with password 'gauss@123' valid until '2001-12-12';
drop role trim;

--step9:作为用户组名;expect:成功
drop group if exists trim;
create group trim with password 'gauss@123';
drop group trim;

--step10:作为模式名;expect:成功
drop schema if exists trim;
create schema trim;
drop schema trim;

--step11:作为序列名;expect:成功
create sequence public.trim start 100 cache 50;
drop sequence public.trim;

--step12:作为用户名;expect:成功
drop user if exists trim;
CREATE USER trim PASSWORD 'Bigdata@123';
drop user trim;

--step13:作为游标名;expect:成功
drop table if exists trim_test cascade;
create table trim_test(cid int,fid int);
start transaction;
cursor trim for select * from trim_test order by 1;
close trim;
end;

--step14:清理环境;expect:成功
drop table if exists trim_test cascade;
drop table if exists trim cascade;
drop table if exists t_trim_0019;